//
//  UIViewTool.swift
//  SwiftDemo
//
//  Created by tenltrs on 2018/8/21.
//  Copyright © 2018年 Tenltrs. All rights reserved.
//

import UIKit

class UIViewTool: NSObject {
    
    static func mas_view(backColor : UIColor?) -> UIView {
        
        let newView=UIView.init();
        newView.backgroundColor=backColor;
        return newView;
    }

    static func mas_label(text : String,textColor : UIColor,textAligment:NSTextAlignment,fontSize:CGFloat)->UILabel{
        
        let label = UILabel.init();
        label.text=text;
        label.textColor=textColor;
        
        let font : UIFont;
        if DEVICEPAD {
            font = UIFont.systemFont(ofSize: fontSize);
        }else if iPhone5{
            font = UIFont.systemFont(ofSize: fontSize*RATIO);
        }else{
            font = UIFont.systemFont(ofSize: fontSize);
        }
        
        label.font=font;
        return label;
    }

    /// 适用于masonry布局的原生ImageView
    ///
    /// - Parameters:
    ///   - backColor: 背景色
    ///   - imageName: 图片
    /// - Returns: 得到一个图片
    static func mas_imageView(backColor : UIColor? ,imageName : String?) -> UIImageView{
        
        let imageView : UIImageView = UIImageView.init();
        if (backColor != nil) {
            imageView.backgroundColor=backColor;
        }
        if (imageName != nil){
            imageView.image=UIImage.init(named: imageName!);
        }
        return imageView;
    }

    /**
    + (UIButton *)mas_buttonWithTitle:(NSString *)title
                            image:(NSString *)image
                  backgroundImage:(NSString *)backGImage
                       titleColor:(UIColor *)titleColor
                             font:(CGFloat)fontSize;
    */
    static func mas_button(title : String?, image : String?, backgroundImage : String?,
                           titleColor : UIColor?, fontSize : CGFloat?) ->UIButton{

        let button = UIButton.init(type: .custom)
        if title != nil{
            button.setTitle(title!, for: .normal)
        }
        if image != nil{
            button.setImage(UIImage(named: image!), for: .normal)
        }
        if backgroundImage != nil{
            button.setBackgroundImage(UIImage(named: backgroundImage!), for: .normal)
        }
        if titleColor != nil{
            button.setTitleColor(titleColor!, for: .normal)
        }
        button.titleLabel!.font = UIFont.systemFont(ofSize: fontSize ?? 16)
        return button
    }
}
